﻿using System.Collections.Generic;

namespace Tuxedo
{
	internal class CsProjData
	{
		public CsProjData(string directory, ICollection<string> codeFiles, ICollection<string> embedFiles)
		{
			this.Initialize(directory, codeFiles, embedFiles);
		}

		protected virtual void Initialize(string directory, ICollection<string> codeFiles, ICollection<string> embedFiles)
		{
			// just code files
			this.CodeFiles = new Dictionary<string, string>();

			// images as bmp data
			this.EmbeddedImages = new Dictionary<string, string>();

			// image bmp data using shorthand notation
			this.EmbeddedShorthandImages = new Dictionary<string, string>();

			// text unencoded (aside from escaped \ and ', etc)
			this.EmbeddedText = new Dictionary<string, string>();

			// text with repeating characters abbreviated
			this.EmbeddedShorthandText = new Dictionary<string, string>();

			// text represented as hexidecimal
			this.EmbeddedBinary = new Dictionary<string, string>();

			foreach (string codeFile in codeFiles)
			{
				string absolutePath = System.IO.Path.Combine(directory, codeFile);
				string contents = FileReader.ReadFile(absolutePath);
				this.CodeFiles[codeFile] = contents;
			}

			foreach (string assetFile in embedFiles)
			{
				string absolutePath = System.IO.Path.Combine(directory, assetFile);
				string contents = FileReader.ReadFile(absolutePath);
				string extension = System.IO.Path.GetExtension(assetFile);
				bool useText = true;
				if (extension != null)
				{
					extension = extension.ToLowerInvariant();
					if (extension == ".png" || extension == ".jpg" || extension == ".jpeg" || extension == ".bmp")
					{
						useText = false;
						this.SaveImage(assetFile, extension, absolutePath);
					}
				}

				if (useText)
				{
					this.EmbeddedText[assetFile] = contents;
				}
			}
		}

		public Dictionary<string, string> CodeFiles { get; private set; }
		public Dictionary<string, string> EmbeddedText { get; private set; }
		public Dictionary<string, string> EmbeddedShorthandText { get; private set; }
		public Dictionary<string, string> EmbeddedBinary { get; private set; }
		public Dictionary<string, string> EmbeddedImages { get; private set; }
		public Dictionary<string, string> EmbeddedShorthandImages { get; private set; }

		private void SaveImage(string relativePath, string extension, string absolutePath)
		{
			// TODO: this
		}
	}
}
